package com.yiren.dbaa.util;

import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.provider.Settings;

/**
 * @author lwb
 * @date : 2022/7/12 11:04
 * @description: 设备信息工具类
 */
public class DeviceUtil {

    /**
     * 获取app版本信息
     *
     * @param context
     * @return
     */
    public static String getAppVersion(Context context) {
        PackageInfo packageInfo = null;
        String appVersion = "";
        try {
            packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            appVersion = ((null == packageInfo) ? "" : "V" + packageInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return appVersion;
    }

    /**
     * 获取APP版本号
     *
     * @param context
     * @return
     */
    public static int getAppCode(Context context) {
        PackageInfo packageInfo = null;
        int appCode = 0;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            appCode = ((null == packageInfo) ? 0 : packageInfo.versionCode);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return appCode;
    }

}
